<?php

class User_Controller_Browse_Edit_Photo extends Nuo_Controller
{
	function execute($request)
	{
		$form = Nuo::getObject('user/photo/upload', 'form');

		$form -> setTitle('Change Profile Avatar');

		$user = Nuo::getUser();

		Nuo::setVar('mainResource', $user);

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$uploads = Nuo_Filesystem::instance() -> getUploads('photo');

			if ($uploads)
			{

				$file = Nuo::getApi('core/image') -> process($uploads, 'user');

				if ($file)
				{
					$user -> setPhotoFile($file) -> save();
				}
			}
		}
		return $form;
	}

}
